package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 6:04 PM
 */
object Test07_Inherit {
  def main(args: Array[String]): Unit = {
    val student1 = new Student7("zs", 20)
    val student2 = new Student7("ls", 22, "2323")
    student1.printInfo()
    student2.printInfo()
  }
}

class Person7() {

  var name: String = _
  var age: Int = _
  println("1.父类主构造被调用")

  def this(name: String, age: Int) {
    this()
    println("2. 父类辅助构造被调用")
    this.name = name
    this.age = age
  }

  def printInfo(): Unit = {
    println(s"Person: name= ${name} age= ${age}")
  }
}

class Student7(name: String, age: Int) extends Person7(name, age) {
  var stdNo: String = _
  println("3.子类主构造器调用")

  def this(name: String, age: Int, stdNo: String) {
    this(name, age)
    println("4.子类辅助构造器调用")
    this.stdNo = stdNo
  }

  override def printInfo(): Unit = {
    println(s"Student7: name= ${name} age= ${age} stdNo=${stdNo}")
  }
}